package bma.common.langutil.runtime;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;

import junit.framework.TestCase;
import bma.common.langutil.concurrent.ScheduledExecutorJava;
import bma.common.langutil.core.ObjectUtil;
import bma.common.langutil.io.IOUtil;

public class RuntimeConfigTC extends TestCase {

	final org.slf4j.Logger log = org.slf4j.LoggerFactory
			.getLogger(RuntimeConfigTC.class);

	public RuntimeConfig config() {
		File file1 = IOUtil.getUserDirFile("test1.txt");
		File file2 = IOUtil.getUserDirFile("test2.txt");
		List<String> files = new ArrayList<String>();
		files.add(file1.getPath());
		files.add(file2.getPath());

		RuntimeConfig r = new RuntimeConfig();
		r.setExecutor(new ScheduledExecutorJava(Executors
				.newScheduledThreadPool(5)));
		r.setFiles(files);
		r.setFileCheckTime(1000);
		return r;
	}

	public void print(RuntimeConfig r) {
		System.out.println(r.getConfig("a"));
		System.out.println(r.getConfig("b"));
		System.out.println(r.getConfig("c"));
	}

	public void testBase() throws Exception {
		RuntimeConfig r = config();
		r.init();
		print(r);
		ObjectUtil.waitFor(this, 10 * 1000);
		print(r);
		r.close();
	}

}
